Skip to content

Add RISC-V scalar fallback support#318

Open
carlosqwqqwq wants to merge 1 commit into
microsoft:mainfrom
carlosqwqqwq:riscv-directxmath
Open

Add RISC-V scalar fallback support#318
carlosqwqqwq wants to merge 1 commit into
microsoft:mainfrom
carlosqwqqwq:riscv-directxmath

Conversation

@carlosqwqqwq

Copy link
Copy Markdown

Why

DirectXMath already contains a full scalar _XM_NO_INTRINSICS_ implementation for its core headers, but non-x86/non-ARM targets are currently rejected in DirectXMath.h before that fallback can be used. For riscv64, this means the library fails during target detection even though the scalar backend is already present and suitable as a conservative portability path.

What changed

  • Updated Inc/DirectXMath.h so __riscv selects the existing _XM_NO_INTRINSICS_ scalar backend instead of falling into the unsupported-target #error.
  • Updated CMakeLists.txt to emit a clear configure-time status message when the target processor matches riscv*.
  • Updated README.md to document that riscv64 currently uses the scalar no-intrinsics backend and does not claim any RISC-V vector or assembly implementation.
  • Updated the x86-only extension headers in Extensions/ (SSE3, SSE4, AVX, AVX2, F16C, FMA3, FMA4) to reject __riscv explicitly instead of implying they are only unsupported on ARM.

Verification

  • Ran native CMake configure/generate successfully:
    • cmake -S . -B build-native -G Ninja -DBUILD_TESTING=OFF -DBUILD_XDSP=OFF -DBUILD_SHMATH=OFF
  • Built and ran a native consumer program that includes DirectXCollision.h and exercises:
    • XMVectorSet
    • XMVectorAdd
    • XMMatrixScaling
    • XMVector4Transform
    • BoundingSphere::Contains
  • Because DirectXMath requires an external sal.h on non-Windows targets, fetched the open-source header referenced by the upstream README:
    • curl -L -o /tmp/sal/sal.h https://raw.githubusercontent.com/dotnet/runtime/v9.0.2/src/coreclr/pal/inc/rt/sal.h
  • Built a real riscv64 consumer with dockcross/linux-riscv64:
    • "$CXX" -std=c++17 -O2 -static -I/tmp/sal -I/repo/Inc -I/repo/Extensions build-riscv-forced/dxmath_smoke.cpp -o /tmp/dxmath_smoke.riscv64
  • Verified the produced binary is a real RISC-V ELF:
    • file /tmp/dxmath_smoke.riscv64
    • readelf -h /tmp/dxmath_smoke.riscv64
  • Ran the binary under qemu-riscv64 successfully:
    • output: dxmath-ok
  • Confirmed that including Extensions/DirectXMathAVX.h under forced __riscv now fails immediately with the intended top-level error:
    • AVX not supported on this platform

Notes

  • This is a conservative portability patch. It enables the existing scalar backend for RISC-V but does not add RVV, custom intrinsics, or assembly kernels.
  • Because DirectXMath is header-only, the most relevant proof is successful consumer compilation through the intended codepath rather than a large library build artifact.
  • The real riscv64 validation uses the upstream-documented external sal.h dependency rather than adding any new compatibility shim inside DirectXMath itself.

@carlosqwqqwq

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant